﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Super.Mvc.Form;

namespace Super.Mvc
{
    public class JsonBack : JsonResult
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ErrorMessage">数据库保存返回值</param>
        /// <param name="navTabId">刷新窗体ID</param>
        /// <param name="message">提示消息</param>
        /// <param name="isClose"> </param>
        /// <returns></returns>
        public static JsonResult Tip(string ErrorMessage, string navTabId = "", string message = "操作成功！",bool isClose=false)
        {
            var jsonEntity = new JsonReturnMessages();
            if (ErrorMessage == null)
            {
                jsonEntity.statusCode = ((int)StatusCode.ok).ToString();
                jsonEntity.callbackType = "";
                jsonEntity.navTabId = navTabId;
                jsonEntity.message = message;
            }
            else
            {
                jsonEntity.statusCode = ((int)StatusCode.error).ToString();
                jsonEntity.callbackType = "";
                jsonEntity.navTabId = navTabId;
                jsonEntity.message = ErrorMessage;
            }

            if(isClose)
            {
                jsonEntity.callbackType = "closeCurrent";
            }

            return new JsonResult
            {
                Data = jsonEntity,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

    }
}
